package com.ymatou.iapi.userservice.testcase;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.QueryWeiXinOpenIdByUserIdReq;
import com.ymatou.iapi.userservice.parameter.WeiXinUserRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.WeiXinUserUnionYmatouUserRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ThirdPartyTypeEnum;
import com.ymatou.iapi.userservice.parameter.req.BindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.WeiXinUserUnionYmatouUserRequestDtoCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.common.enums.ChannelSourceEnum;
import com.ymttest.common.enums.UserTerminalSourceEnum;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
*用户微信账号关联其码头账号接口
*/
@TestSuite
public class Ts_WeiXinUserUnionYmatouUserRequestDto {

	private static QueryWeiXinOpenIdByUserIdReq weixinuserunionymatouuserrequestdtobean;
	private static WeiXinUserUnionYmatouUserRequestDtoCall weixinuserunionymatouuserrequestdtocall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("用户微信账号关联其码头账号接口");
	}

	@Before
	public void caseUp() {
		weixinuserunionymatouuserrequestdtobean=new QueryWeiXinOpenIdByUserIdReq();
		weixinuserunionymatouuserrequestdtocall=new WeiXinUserUnionYmatouUserRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(weixinuserunionymatouuserrequestdtocall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_WeiXinUserUnionYmatouUserRequestDto_001(){
		Logger.start(true,"查询微信是否关联洋码头账号成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			weixinuserunionymatouuserrequestdtobean.setRegSource(AppSourceEnum.App);
			weixinuserunionymatouuserrequestdtobean.setUserId(uid);
			weixinuserunionymatouuserrequestdtocall.setData(weixinuserunionymatouuserrequestdtobean);
			weixinuserunionymatouuserrequestdtocall.callService();
			Logger.verifyEquals("true", weixinuserunionymatouuserrequestdtocall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.SUCCESS, weixinuserunionymatouuserrequestdtocall.getString("ResponseCode"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_WeiXinUserUnionYmatouUserRequestDto_002(){
		Logger.start(false,"查询未关联用户,成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
//			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
//			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
//			JUserCallService.bindThirdPartyUserCall(bd);
			weixinuserunionymatouuserrequestdtobean.setRegSource(AppSourceEnum.App);
			weixinuserunionymatouuserrequestdtobean.setUserId(uid);
			weixinuserunionymatouuserrequestdtocall.setData(weixinuserunionymatouuserrequestdtobean);
			weixinuserunionymatouuserrequestdtocall.callService();
			Logger.verifyEquals("false", weixinuserunionymatouuserrequestdtocall.getString("Success"), "验证是否成功");

			Logger.verifyEquals("404", weixinuserunionymatouuserrequestdtocall.getString("ResponseCode"), "验证Code");
			Logger.verifyIsContains("用户不存在或未绑定", weixinuserunionymatouuserrequestdtocall.getString("LastErrorMessage"), "验证LastErrorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_WeiXinUserUnionYmatouUserRequestDto_003(){
		Logger.start(false,"不输入UId,失败");
		try {
			weixinuserunionymatouuserrequestdtobean.setRegSource(AppSourceEnum.App);
			weixinuserunionymatouuserrequestdtocall.setData(weixinuserunionymatouuserrequestdtobean);
			weixinuserunionymatouuserrequestdtocall.callService();
			Logger.verifyEquals("404", weixinuserunionymatouuserrequestdtocall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", weixinuserunionymatouuserrequestdtocall.getString("Success"), "验证是否成功");
//			Logger.verifyIsContains("userid must gte 1", weixinuserunionymatouuserrequestdtocall.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_WeiXinUserUnionYmatouUserRequestDto_004(){
		Logger.start(false,"不输入RegSource,失败");
		try {
			weixinuserunionymatouuserrequestdtobean.setUserId(1);
			weixinuserunionymatouuserrequestdtocall.setData(weixinuserunionymatouuserrequestdtobean);
			weixinuserunionymatouuserrequestdtocall.callService();
			Logger.verifyEquals("404", weixinuserunionymatouuserrequestdtocall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", weixinuserunionymatouuserrequestdtocall.getString("Success"), "验证是否成功");
//			Logger.verifyIsContains("regSource can't null", weixinuserunionymatouuserrequestdtocall.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_WeiXinUserUnionYmatouUserRequestDto_005(){
		Logger.start(false,"不输入用户Id,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			weixinuserunionymatouuserrequestdtobean.setRegSource(AppSourceEnum.App);
			weixinuserunionymatouuserrequestdtocall.setData(weixinuserunionymatouuserrequestdtobean);
			weixinuserunionymatouuserrequestdtocall.callService();
			Logger.verifyEquals("404", weixinuserunionymatouuserrequestdtocall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", weixinuserunionymatouuserrequestdtocall.getString("Success"), "验证是否成功");
//			Logger.verifyIsContains("userId:userid must gte 1", weixinuserunionymatouuserrequestdtocall.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_WeiXinUserUnionYmatouUserRequestDto_006(){
		Logger.start(true,"查询微信是否关联洋码头账号成功GlobalWxApp");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			bd.setAppSource(AppSourceEnum.GlobalWxApp);
			JUserCallService.bindThirdPartyUserCall(bd);
			weixinuserunionymatouuserrequestdtobean.setRegSource(AppSourceEnum.GlobalWxApp);
			weixinuserunionymatouuserrequestdtobean.setUserId(uid);
			weixinuserunionymatouuserrequestdtocall.setData(weixinuserunionymatouuserrequestdtobean);
			weixinuserunionymatouuserrequestdtocall.callService();
			Logger.verifyEquals("true", weixinuserunionymatouuserrequestdtocall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.SUCCESS, weixinuserunionymatouuserrequestdtocall.getString("ResponseCode"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
